package com.mock.ems.controller.config;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.mock.ems.common.JsonResult;

public class ScoreConfigController extends Controller {

    public void index(){

        Record record = Db.findFirst("select * from score_config order by id desc");
        if (null != record) {
            record.set("banners",record.getStr("banners").split(","));
            record.set("urls",record.getStr("urls").split(","));
            record.set("scores",record.getStr("scores").split(","));
            setAttr("score",record.getColumns());
        }
        render("/page/config/score/score_config.jsp");
    }

    @Before(Tx.class)
    public void save(){

        String scores = getPara("scores");

        //处理banners
        String banners = getPara("banners");
        String urls = getPara("bannerUrls");

        Record record = Db.findFirst("select * from score_config order by id desc");
        record.set("banners",banners).set("urls",urls).set("scores",scores);

        Db.update("score_config",record);

        renderJson(new JsonResult().status("000").show("保存成功"));
    }

}
